package tcpService

import (
	"fmt"
	"net"
	"InstantImage/config"
	"InstantImage/util"
)

type TcpService struct {
	SetPool util.ConnPools
	GetPool util.ConnPools
	DelPool util.ConnPools
	DBMsg   string
	CurMsg  string
}

func NewTcpService() *TcpService {
	return &TcpService{
		SetPool: util.NewConnPool(100, func() (net.Conn, error) {
			return net.Dial("tcp", fmt.Sprintf("%s:%s", config.DatabaseIp, config.DatabasePort))
		}),
		GetPool: util.NewConnPool(100, func() (net.Conn, error) {
			return net.Dial("tcp", fmt.Sprintf("%s:%s", config.DatabaseIp, config.DatabasePort))
		}),
		DelPool: util.NewConnPool(100, func() (net.Conn, error) {
			return net.Dial("tcp", fmt.Sprintf("%s:%s", config.DatabaseIp, config.DatabasePort))
		}),
		DBMsg:  fmt.Sprintf("%s:%s", config.DatabaseIp, config.DatabasePort),
		CurMsg: fmt.Sprintf("%s:%s", config.CurIp, config.CurPort),
	}
}
